function Util(){
	this.baseUrl = 'http://api.shihou.tv/api/user/batch?';
	this.user_ids = [841541, 635689, 584559, 1097247, 532936, 554926];
	this.init();
}
Util.prototype={
	init: function(){
		
	},
	setAnchorInfo: function(page){
		var _this = this;
		
		var url = _this.baseUrl;
		console.log("开始加载用户信息");
		for (var i = 0 ; i < _this.user_ids.length; i++) {
			var user_id = _this.user_ids[i];
			url += "&user_ids[]="+user_id;
		}
		_this.requestRemoteDataJson(url, {}, function(result){
			if(_this.parseResult(result, 'error') == 0){
				var users = _this.parseResult(result, 'data', 'users');
				for (var i = 0;i < users.length; i++){
					var user = users[i];
					var user_id = _this.parseResult(user, 'id');
					var avatar = _this.parseResult(user, 'avatar');
					var room_id = _this.parseResult(user, 'room', 'id');
					var vdo_status = _this.parseResult(user, 'room', 'vdo_status');
					
					_this.setLiveStatus(user_id, avatar, room_id, vdo_status, page);
				}
				console.log("用户信息加载完毕");
			}
		});
	},
	setLiveStatus:function(user_id, avatar, room_id, vdo_status, page){
		var _this = this;
		var object = $('#'+user_id+"-img");
		var object_a = object.parent().parent().find('a');
		var index = object.parent().index();
		var live_html = '<div class="phbWrap">'+
		                '    <em></em>'+
		                '    <span></span>'+
		                '    <div class="loader-inner line-scale-pulse-out">'+
		                '        <div></div>'+
		                '        <div></div>'+
		                '        <div></div>'+
		                '        <div></div>'+
		                '        <div></div>'+
		                '    </div>'+
		            	'</div>';
		if(vdo_status == 1){
			object.after(live_html);
		}
		if(page == 0){
			object_a.eq(index-1).attr("href", "http://shihoutv://route?jump_type=20&jump_id="+room_id);
			object_a.eq(index+1).attr("href", "http://shihoutv://route?jump_type=20&jump_id="+room_id);
		}else if(page == 1){
			object_a.eq(index-1).attr("href", "http://m.shihou.tv/redirect_room?room_id="+room_id);
			object_a.eq(index+1).attr("href", "http://m.shihou.tv/redirect_room?room_id="+room_id);
		}
		object.attr("src", avatar);
	},
	//获取url中的参数
    getUrlParam: function(name, url) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
        url = url || window.location.search.substr(1).match(reg);  //匹配目标参数
        if (url != null) return unescape(url[2]); return null; //返回参数值
    },
    getUrlParams: function(){
    	var url = window.location.href;  //匹配目标参数
    	if(url != null)
    		return url.substr(url.indexOf("?"), url.length);
    },
    parseResult:function(){//解析结果， 如果不存在则返回''
		var size = arguments.length;
		if(size == 0){
			return '';
		}
		var result = arguments[0];
		for(var i = 1; i < size; i++){
			if(result == undefined){
				return '';
			}
			var argu = arguments[i];
			if(i == size){
				return argu;
			}
			result = result[argu];
		}
		return result;
	},
	requestRemoteDataJson: function(url, data, callback, asyn){
		$.ajax({
	        url: url,
	        type: 'GET',
	        async: asyn | true,
	        cache: false, 
	        dataType: "json",
	        data: data,
	        success: callback,
	        error: function (data) {
	        	var status = data.status;
	        	console.log(url + "获取数据失败!");
	        }
	    });
	},
	log:function(data){
		console.log(data);
	},
	logURL:function(url){
		console.log("url --> "+url);
	},
	logParameter:function(data){
		console.log("parameter --> "+JSON.stringify(data));
	},
	logResult:function(result){
		console.log("result --> "+JSON.stringify(result));
	}
}
